package com.neo.web;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.neo.util.IrrUtil;
import com.neo.entity.Mytest;
import com.neo.entity.User;
import com.neo.util.ComputerUtil;
import com.neo.util.HpjParamer;
import com.neo.util.InsertInfoToExcel;
import com.neo.util.ListToMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neo.entity.UserEntity;
import com.neo.mapper.UserMapper;

@RestController
public class UserController {
	
	@Autowired
	private UserMapper userMapper;
	
	@RequestMapping("/getUsers")
	public List<UserEntity> getUsers() {
		List<UserEntity> users=userMapper.getAll();
		return users;
	}
	
    @RequestMapping("/getUser")
    public UserEntity getUser(Long id) {
    	UserEntity user=userMapper.getOne(id);
        return user;
    }
    
    @RequestMapping("/add")
    public void save(UserEntity user) {
    	userMapper.insert(user);
    }
    
    @RequestMapping(value="update")
    public void update(UserEntity user) {
    	userMapper.update(user);
    }
    
    @RequestMapping(value="/delete/{id}")
    public void delete(@PathVariable("id") Long id) {
    	userMapper.delete(id);
    }
    @RequestMapping("/getUsersodAll")
    public List<User> getUsersodAll() {
        List<User> users=userMapper.getAllofUser();
        return users;
    }
   // insertcomputer
   @RequestMapping("/insertcomputer")
   public void insertcomputer() {
	    List<Mytest> list=new ArrayList<>();
       try {
           list=      InsertInfoToExcel.setExcelData( "/home/bruobuqi001/Documents/beifeng/CloudStation/临时文件/10 尚义一期50MW.xlsx","后评价输入界面");
       } catch (Exception e) {
           e.printStackTrace();
       }
       userMapper.insertcomputer(list);
   }

   //获取数据
   @RequestMapping(value="gettest")
   public List<HpjParamer>  gettest() throws Exception {
      List<HpjParamer> list;
       List<HpjParamer> list1;
       list = userMapper.getHpjParamerfrom();

       ComputerUtil computerUtil=new ComputerUtil(ListToMap.getListToMap(list));
       list1=    computerUtil.jingxianjingliuliang44("0.975");
       List list2=new ArrayList();
       Collections.sort(list1);
       for (HpjParamer hpjParamer: list1 ) {
           String str=       hpjParamer.getComputer();

           Double dstr=Double.valueOf(str);
           list2.add(dstr);
       }
       Double ssss=     IrrUtil.ceshi(list2);
       System.out.println(String.valueOf(ssss));
      return computerUtil.jingxianjingliuliang44("0.975");
   }
}